//
//  XJHomeTagView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/22.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJHomeTagView.h"
@interface XJHomeTagView()
@property(nonatomic, strong) UIImageView *iconIv;//图片
@property(nonatomic, strong) UILabel *nameLb; //文字

@end

@implementation XJHomeTagView

#pragma mark - 一 lazy
- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [UIImageView new];
        
    }
    return _iconIv;
}
- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        _nameLb.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLb;
}



#pragma mark - 二 init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
        
        //添加手势
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tagGesAction:)];
        [self addGestureRecognizer:tapGes];
    }
    return self;
}

//h:80 , w:80
- (void)setupView {
    CGFloat w = self.frame.size.width;
//    CGFloat h = self.frame.size.height;
    
    CGFloat iconw = 38;
    if (UI_IS_IPHONE5) {
        iconw = 38;
    }else {
        iconw = 48;
    }
    
    self.iconIv.frame = CGRectMake((w-iconw)/2, 0, iconw, iconw);
    [self addSubview:self.iconIv];
    
    self.nameLb.frame = CGRectMake(0, iconw*1.2, w, 30);
    [self addSubview:self.nameLb];
}

#pragma mark - 三 赋值
- (void)setTagModel:(HomeTagsModel *)tagModel {
    
    _tagModel = tagModel;
    
    UIImage *placeholdeImg = [UIImage imageNamed:@"default_goods"];
    [self.iconIv sd_setImageWithURL:[NSURL URLWithString:tagModel.icon] placeholderImage:placeholdeImg];
    
    self.nameLb.text = tagModel.name;
}

#pragma mark - 四 点击事件
- (void)tagGesAction:(UITapGestureRecognizer *)tap {
    
    if (self.homeTagViewBlock) {
        self.homeTagViewBlock(self.tagModel);
    }
}


@end
